package com.qf.sy2103.ssm.Servlet;



import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/code")
public class CodeServlet extends HttpServlet {

    //生成hutool的验证码
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws  IOException {
        //生成验证码
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 100, 4, 4);
        String code=captcha.getCode();//获取到生成的验证码
        //将验证码存在作用域中
        req.getSession().setAttribute("code",code);
//        System.out.println(code);
        captcha.write(resp.getOutputStream());
    }
}
